package edu.avans.hartigehap.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

//import edu.avans.hartigehap.domain.decorator.AbstractMenuItem;
//import edu.avans.hartigehap.domain.decorator.MenuItemDecorator;

/**
 * 
 * @author Erco
 */
@Entity
@Table(name = "INGREDIENTS")
// optional
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id")
public class Ingredient implements Serializable {
	private static final long serialVersionUID = 1L;
	private String ingredientName;
	private Collection<Restaurant> restaurants = new ArrayList<Restaurant>();
	//private String ingredientName;
	private int ingredientPrice;

	// TODO nog niet af
	
	public Ingredient(String ingredientName, int ingredientPrice)
	{
		this.ingredientName = ingredientName;
		this.ingredientPrice = ingredientPrice;
	}
	
	public Ingredient()
	{
		
	}
	
//	public Ingredient(AbstractMenuItem decoratedMenuItem) {
//		super(decoratedMenuItem);
//		// TODO Auto-generated constructor stub
//	}
//	
//	public Ingredient(AbstractMenuItem decoratedMenuItem, String ingredientName, int ingredientPrice) {
//		super(decoratedMenuItem);
//		this.ingredientName = ingredientName;
//		this.ingredientPrice = ingredientPrice;
//		// TODO Auto-generated constructor stub
//	}

	@Id
	//@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "INGREDIENT_ID")
	public String getId() {
		return ingredientName;
	}

	public void setId(String id) {
		this.ingredientName = id;
	}
	
	/*public void setPice(int ingredientPrice)
	{
		this.ingredientPrice = ingredientPrice;
	}*/

	public int getPrice() 
	{
//		if(super.decoratedPizza != null)
//		{
//			return super.getPrice() + getIngredientPrice();
//		}
//		else
//		{
		return this.ingredientPrice;
		//}
	}

	public void setPrice(int ingredientPrice) {
		this.ingredientPrice = ingredientPrice;
	}
	
	@Transient
	public int getIngredientPrice()
	{
		return ingredientPrice;
	}
	
	@ManyToMany(cascade = javax.persistence.CascadeType.ALL)
	public Collection<Restaurant> getRestaurants() {
		return restaurants;
	}

	public void setRestaurants(Collection<Restaurant> restaurants) {
		this.restaurants = restaurants;
	}
	
}
